

#ifndef SMDEVP_H
#define SMDEVP_H

#include "stdsoap2.h"

#include <openssl/evp.h>
#include <openssl/hmac.h>
#include <openssl/ssl.h>

#ifdef __cplusplus
extern "C" {
#endif

#define SOAP_SMD_KEY_TYPE       EVP_PKEY

#define SOAP_SMD_MAX_SIZE       EVP_MAX_MD_SIZE

#define SOAP_SMD_MD5_SIZE       (16)

#define SOAP_SMD_SHA1_SIZE      (20)

#define SOAP_SMD_SHA224_SIZE    (28)

#define SOAP_SMD_SHA256_SIZE    (32)

#define SOAP_SMD_SHA384_SIZE    (48)

#define SOAP_SMD_SHA512_SIZE    (64)

#define SOAP_SMD_NONE   (0x0000)
#define SOAP_SMD_HASH   (0x000F)
#define SOAP_SMD_ALGO   (0x0030)
#define SOAP_SMD_MASK   (0x01FF)

#define SOAP_SMD_MD5    (0x00)

#define SOAP_SMD_SHA1   (0x01)

#define SOAP_SMD_SHA224 (0x02)

#define SOAP_SMD_SHA256 (0x03)

#define SOAP_SMD_SHA384 (0x04)

#define SOAP_SMD_SHA512 (0x05)

#define SOAP_SMD_HMAC   (0x00)

#define SOAP_SMD_DGST   (0x10)

#define SOAP_SMD_SIGN   (0x20)

#define SOAP_SMD_VRFY   (0x30)

#define SOAP_SMD_DSA    (0x40)

#define SOAP_SMD_ECDSA  (0x80)

#define SOAP_SMD_PASSTHRU        (0x100)

#define SOAP_SMD_HMAC_MD5        (SOAP_SMD_HMAC | SOAP_SMD_MD5)

#define SOAP_SMD_HMAC_SHA1       (SOAP_SMD_HMAC | SOAP_SMD_SHA1)

#define SOAP_SMD_HMAC_SHA224     (SOAP_SMD_HMAC | SOAP_SMD_SHA224)

#define SOAP_SMD_HMAC_SHA256     (SOAP_SMD_HMAC | SOAP_SMD_SHA256)

#define SOAP_SMD_HMAC_SHA384     (SOAP_SMD_HMAC | SOAP_SMD_SHA384)

#define SOAP_SMD_HMAC_SHA512     (SOAP_SMD_HMAC | SOAP_SMD_SHA512)

#define SOAP_SMD_DGST_MD5        (SOAP_SMD_DGST | SOAP_SMD_MD5)

#define SOAP_SMD_DGST_SHA1       (SOAP_SMD_DGST | SOAP_SMD_SHA1)

#define SOAP_SMD_DGST_SHA224     (SOAP_SMD_DGST | SOAP_SMD_SHA224)

#define SOAP_SMD_DGST_SHA256     (SOAP_SMD_DGST | SOAP_SMD_SHA256)

#define SOAP_SMD_DGST_SHA384     (SOAP_SMD_DGST | SOAP_SMD_SHA384)

#define SOAP_SMD_DGST_SHA512     (SOAP_SMD_DGST | SOAP_SMD_SHA512)

#define SOAP_SMD_SIGN_RSA_MD5    (SOAP_SMD_SIGN | SOAP_SMD_MD5)

#define SOAP_SMD_SIGN_RSA_SHA1   (SOAP_SMD_SIGN | SOAP_SMD_SHA1)

#define SOAP_SMD_SIGN_RSA_SHA224 (SOAP_SMD_SIGN | SOAP_SMD_SHA224)

#define SOAP_SMD_SIGN_RSA_SHA256 (SOAP_SMD_SIGN | SOAP_SMD_SHA256)

#define SOAP_SMD_SIGN_RSA_SHA384 (SOAP_SMD_SIGN | SOAP_SMD_SHA384)

#define SOAP_SMD_SIGN_RSA_SHA512 (SOAP_SMD_SIGN | SOAP_SMD_SHA512)

#define SOAP_SMD_SIGN_DSA_MD5    (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_MD5)

#define SOAP_SMD_SIGN_DSA_SHA1   (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA1)

#define SOAP_SMD_SIGN_DSA_SHA224 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA224)

#define SOAP_SMD_SIGN_DSA_SHA256 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA256)

#define SOAP_SMD_SIGN_DSA_SHA384 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA384)

#define SOAP_SMD_SIGN_DSA_SHA512 (SOAP_SMD_SIGN | SOAP_SMD_DSA | SOAP_SMD_SHA512)

#define SOAP_SMD_SIGN_ECDSA_MD5    (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_MD5)

#define SOAP_SMD_SIGN_ECDSA_SHA1   (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_SHA1)

#define SOAP_SMD_SIGN_ECDSA_SHA224 (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_SHA224)

#define SOAP_SMD_SIGN_ECDSA_SHA256 (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_SHA256)

#define SOAP_SMD_SIGN_ECDSA_SHA384 (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_SHA384)

#define SOAP_SMD_SIGN_ECDSA_SHA512 (SOAP_SMD_SIGN | SOAP_SMD_ECDSA | SOAP_SMD_SHA512)

#define SOAP_SMD_VRFY_RSA_MD5    (SOAP_SMD_VRFY | SOAP_SMD_MD5)

#define SOAP_SMD_VRFY_RSA_SHA1   (SOAP_SMD_VRFY | SOAP_SMD_SHA1)

#define SOAP_SMD_VRFY_RSA_SHA224 (SOAP_SMD_VRFY | SOAP_SMD_SHA224)

#define SOAP_SMD_VRFY_RSA_SHA256 (SOAP_SMD_VRFY | SOAP_SMD_SHA256)

#define SOAP_SMD_VRFY_RSA_SHA384 (SOAP_SMD_VRFY | SOAP_SMD_SHA384)

#define SOAP_SMD_VRFY_RSA_SHA512 (SOAP_SMD_VRFY | SOAP_SMD_SHA512)

#define SOAP_SMD_VRFY_DSA_MD5    (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_MD5)

#define SOAP_SMD_VRFY_DSA_SHA1   (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA1)

#define SOAP_SMD_VRFY_DSA_SHA224 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA224)

#define SOAP_SMD_VRFY_DSA_SHA256 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA256)

#define SOAP_SMD_VRFY_DSA_SHA384 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA384)

#define SOAP_SMD_VRFY_DSA_SHA512 (SOAP_SMD_VRFY | SOAP_SMD_DSA | SOAP_SMD_SHA512)

#define SOAP_SMD_VRFY_ECDSA_MD5    (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_MD5)

#define SOAP_SMD_VRFY_ECDSA_SHA1   (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_SHA1)

#define SOAP_SMD_VRFY_ECDSA_SHA224 (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_SHA224)

#define SOAP_SMD_VRFY_ECDSA_SHA256 (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_SHA256)

#define SOAP_SMD_VRFY_ECDSA_SHA384 (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_SHA384)

#define SOAP_SMD_VRFY_ECDSA_SHA512 (SOAP_SMD_VRFY | SOAP_SMD_ECDSA | SOAP_SMD_SHA512)

struct soap_smd_data {
  int alg;              
  void *ctx;            
  const void *key;      
  int (*fsend)(struct soap*, const char*, size_t);
  size_t (*frecv)(struct soap*, char*, size_t);
  soap_mode mode;       
};

SOAP_FMAC1 size_t SOAP_FMAC2 soap_smd_size(int alg, const void *key);

SOAP_FMAC1 int SOAP_FMAC2 soap_smd_begin(struct soap *soap, int alg, const void *key, int keylen);
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_end(struct soap *soap, char *buf, int *len);

SOAP_FMAC1 int SOAP_FMAC2 soap_smd_init(struct soap *soap, struct soap_smd_data *data, int alg, const void *key, int keylen);
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_update(struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len);
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_final(struct soap *soap, struct soap_smd_data *data, char *buf, int *len);
SOAP_FMAC1 void SOAP_FMAC2 soap_smd_cleanup(struct soap *soap, struct soap_smd_data *data);

#ifdef __cplusplus
}
#endif

#endif
